package com.scsj.supermarket.presenter;

import android.util.Log;

import com.scsj.supermarket.base.IndexBase;
import com.scsj.supermarket.base.ShopCarBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.bean.IndexBean;
import com.scsj.supermarket.bean.ShopCarBean;
import com.scsj.supermarket.model.IndexModel;
import com.scsj.supermarket.model.ShopCarModel;

import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 购物车
 */

public class ShopCarPresenter extends BasePresenter implements ShopCarBase.IPresenter {

    private ShopCarBase.IModel mModel;
    private ShopCarBase.IView mView;

    public ShopCarPresenter(ShopCarBase.IView view) {
        mView = view;
        mModel = new ShopCarModel();
    }

    @Override
    public void deliverAllList() {
        addSubscription(mModel.getAllData(new ResponseCallback<ShopCarBean>() {
            @Override
            public void onSuccess(ShopCarBean result) {

                if (result.getStatusCode() == 200) {

                    mView.showSuccessMsg("购物车数据拿到了，sb");
                    mView.setAllData(result);

                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverShopCarDel(RequestBody requestBody) {
        addSubscription(mModel.getShopCarDelData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {

                if (result.getStatusCode() == 200) {

                    mView.showSuccessMsg("商品删除成功，sb");
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {

                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");

            }
        }));
    }

    @Override
    public void deliverShopCarSendFare(RequestBody requestBody) {

        addSubscription(mModel.getShopCarSendFareData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {

                if (result.getStatusCode() == 200) {

                    mView.showSuccessMsg("运费获取成功，sb");
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("onFaild", msg + "");
            }
        }));

    }
}
